home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
bgiherc.zip
/
BGIDEMO.C
next >
Wrap
Text File
|
1989-05-31
|
40KB
|
1,402 lines
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88 Borland International. All rights reserved.
Altered (modestly) to support the Hercules InColor Card using the
"unified" HERC.BGI driver.
*/
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <graphics.h>
#define ESC 0x1b /* Define the escape key */
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};
char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};
char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};
char *TextDirect[] = {
"HorizDir", "VertDir"
};
char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};
char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};
struct PTS {
int x, y;
}; /* Structure to hold vertex points */
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int MaxX, MaxY; /* The maximum resolution of the screen */
int MaxColors; /* The maximum # of colors available */
int ErrorCode; /* Reports any graphics errors */
struct palettetype palette; /* Used to read palette info */
/* */
/* Function prototypes */
/* */
void Initialize(void);
void ReportStatus(void);
void TextDump(void);
void Bar3DDemo(void);
void RandomBars(void);
void TextDemo(void);
void ColorDemo(void);
void ArcDemo(void);
void CircleDemo(void);
void PieDemo(void);
void BarDemo(void);
void LineRelDemo(void);
void PutPixelDemo(void);
void PutImageDemo(void);
void LineToDemo(void);
void LineStyleDemo(void);
void CRTModeDemo(void);
void UserLineStyleDemo(void);
void FillStyleDemo(void);
void FillPatternDemo(void);
void PaletteDemo(void);
void PolyDemo(void);
void SayGoodbye(void);
void Pause(void);
void MainWindow(char *header);
void StatusLine(char *msg);
void DrawBorder(void);
void changetextstyle(int font, int direction, int charsize);
int gprintf(int *xloc, int *yloc, char *fmt, ... );
/* */
/* Begin main function */
/* */
int main()
{
Initialize(); /* Set system into Graphics mode */
ReportStatus(); /* Report results of the initialization */
ColorDemo(); /* Begin actual demonstration */
if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
PaletteDemo();
if( GraphDriver==HERCMONO && (getmaxcolor() == 15)) /* Test for InColor */
PaletteDemo();
PutPixelDemo();
PutImageDemo();
Bar3DDemo();
BarDemo();
RandomBars();
ArcDemo();
CircleDemo();
PieDemo();
LineRelDemo();
LineToDemo();
LineStyleDemo();
UserLineStyleDemo();
TextDump();
TextDemo();
CRTModeDemo();
FillStyleDemo();
FillPatternDemo();
PolyDemo();
SayGoodbye(); /* Give user the closing screen */
closegraph(); /* Return the system to text mode */
return(0);
}
/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */
void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/
GraphDriver = DETECT;
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
getpalette( &palette ); /* Read the palette from board */
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/
MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */
getaspectratio( &xasp, &yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */
}
/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */
void ReportStatus(void)
{
struct viewporttype viewinfo; /* Params for inquiry procedures*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;
char *driver, *mode; /* Strings for driver and mode */
int x, y;
getviewsettings( &viewinfo );
getlinesettings( &lineinfo );
getfillsettings( &fillinfo );
gettextsettings( &textinfo );
getpalette( &palette );
x = 10;
y = 4;
MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );
driver = getdrivername();
mode = getmodename(GraphMode); /* get current setting */
gprintf( &x, &y, "Graphics device : %-20s (%d)", driver, GraphDriver );
gprintf( &x, &y, "Graphics mode : %-20s (%d)", mode, GraphMode );
gprintf( &x, &y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
gprintf( &x, &y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( &x, &y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );
gprintf( &x, &y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( &x, &y, "Colors available : %d", MaxColors );
gprintf( &x, &y, "Current color : %d", getcolor() );
gprintf( &x, &y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( &x, &y, "Line thickness : %d", lineinfo.thickness );
gprintf( &x, &y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( &x, &y, "Current fill color : %d", fillinfo.color );
gprintf( &x, &y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( &x, &y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( &x, &y, "Character size : %d", textinfo.charsize );
gprintf( &x, &y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( &x, &y, "Vertical justify : %s", VertJust[ textinfo.vert ] );
Pause(); /* Pause for user to read screen*/
}
/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */
void TextDump()
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };
char buffer[80];
int font, ch, wwidth, lwidth, size;
struct viewporttype vp;
for( font=0 ; font<5 ; ++font ){ /* For each available font */
sprintf( buffer, "%s Character Set", Fonts[font] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( &vp ); /* read current viewport */
settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );
buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */
if( font == DEFAULT_FONT ){
changetextstyle( font, HORIZ_DIR, 1 );
ch = 0;
while( ch < 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) > wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{
size = (MaxY < 200) ? CGASizes[font] : NormSizes[font];
changetextstyle( font, HORIZ_DIR, size );
ch = '!'; /* Begin at 1st printable */
while( ch < 127 ){ /*